<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "sys_message".
 *
 * @property integer $id
 * @property integer $create_time
 * @property integer $type
 * @property integer $icon
 * @property string $title
 * @property string $content
 */
class SysMessage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
	public $send_time_1;
    public static function tableName()
    {
        return 'sys_message';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['create_time', 'type', 'icon','send_time','status'], 'integer'],
            [['content'], 'string'],
            [['title'], 'string', 'max' => 256],
            [['title','content'],'required'],
            ['send_time_1','string', 'max' => 50],
            ['send_time_1','checkTime'],
        ];
    }
    public function checkTime($attribute,$params)
    {
    	if(strtotime($this->send_time_1) < time()+ 60 )
    	{
    		return $this->addError($attribute,'发送时间需设置在1分钟后');
    		//return false;
    	}
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'create_time' => Yii::t('app','Create Time'),
            'type' => Yii::t('app','Message Type'),
            'icon' => Yii::t('app','Message Icon'),
            'title' => Yii::t('app','Message Title'),
            'content' => Yii::t('app','Message Content'),
            'send_time' => Yii::t('app','Message Send Time'),
            'status' => Yii::t('app','Message Status'),
        ];
    }

    public function getIconImg0()
    {
        return $this->hasOne(Image::className(), ['id' => 'icon']);
    }
}
